﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity.ModelConfiguration;
using BBICMS.Model;
using System.ComponentModel.DataAnnotations.Schema;

namespace BBICMS.Repository.Configuration
{
   public  class ProductMap:EntityTypeConfiguration<Product>
    {
       public ProductMap()
       {
           this.HasKey(p => p.Id);
            this.Property(p => p.Id)
            .HasColumnName("Id")
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            this.ToTable("Products");

            this.Property(p => p.ProductNo).IsRequired().HasMaxLength(50);
            this.Property(p => p.Title).HasMaxLength(100);
            this.Property(p => p.Thumbnail).HasMaxLength(150);         
           this.Property(p => p.AddedDate).IsRequired().HasColumnType("datetime");
           this.Property(p => p.AddedBy).HasMaxLength(50);
           this.Property(p => p.UpdatedDate).IsOptional().HasColumnType("datetime");
           this.Property(p => p.UpdatedBy).IsOptional().HasMaxLength(50);


            //this.HasMany(a => a.Categories).WithMany(b => b.Products).Map(m =>
            //{
            //    m.MapLeftKey("ProductId");
            //    m.MapRightKey("CategoryId");
            //    m.ToTable("ProductCategory");
            //});
         
            this.HasRequired(l => l.Category).WithMany(l => l.Products).HasForeignKey(l => l.CategoryId);

        
       }
    }
}
